package com.czl.base.data.bean.tengyun;

import android.os.Parcel;
import android.os.Parcelable;

import com.czl.base.data.bean.tengyun.ProductBean;
import com.czl.base.data.bean.tengyun.SortBean;

import java.io.Serializable;
import java.util.List;

/**
 * @author by xubin,
 * @date on 2022/2/10.
 * PS: Not easy to write code, please indicate.
 */
public class BorrowBean implements Serializable, Parcelable {

    private static final long serialVersionUID = 7662687249541797179L;
    private String code;
    private String count;
    /**
     * dealtNum : 2
     * borrowId : 27
     * borrowPersonName : 潘颖
     * borrowApprover : 潘颖
     * checkDate : 1561713589000
     * borrowCode : AJY19062800212
     */

    private int lendNum;
    private int dealtNum;
    private int returnNum;
    private int applyNum;
    private int borrowId;
    private int applyId;
    private String borrowPersonName;
    private String borrowApprover;
    private String approveUserName;
    private String approveUserId;
    private String checkDate;
    private String moReturnDate;
    private String returnDate;
    private String borrowDate;
    private String applyDate;
    private String borrowCode;
    private String borrowPersonDepartment;
    private String borrowOrganizationName;
    private String borrowName;
    private String borrowCompanyName;
    private String borrowComment;
    private String applyComment;
    private String note;
    private String borrowTotalTextNum;
    private int borrowPersonId;
    private int stockNum;
    private List<SortBean> sortList;
    private List<SortBean> borrowSortViewList;
    private List<ProductBean> borrowProductViewList;
    private String returnComment;
    private long date;
    private int num;
    private String userName;
    private int userId;
    private int totalDamageNum;

    protected BorrowBean(Parcel in) {
        code = in.readString();
        count = in.readString();
        lendNum = in.readInt();
        dealtNum = in.readInt();
        returnNum = in.readInt();
        applyNum = in.readInt();
        borrowId = in.readInt();
        applyId = in.readInt();
        borrowPersonName = in.readString();
        borrowApprover = in.readString();
        approveUserName = in.readString();
        approveUserId = in.readString();
        checkDate = in.readString();
        moReturnDate = in.readString();
        returnDate = in.readString();
        borrowDate = in.readString();
        applyDate = in.readString();
        borrowCode = in.readString();
        borrowPersonDepartment = in.readString();
        borrowOrganizationName = in.readString();
        borrowName = in.readString();
        borrowCompanyName = in.readString();
        borrowComment = in.readString();
        applyComment = in.readString();
        note = in.readString();
        borrowTotalTextNum = in.readString();
        borrowPersonId = in.readInt();
        stockNum = in.readInt();
        sortList = in.createTypedArrayList(SortBean.CREATOR);
        borrowSortViewList = in.createTypedArrayList(SortBean.CREATOR);
//        borrowProductViewList = in.createTypedArrayList(ProductBean.CREATOR);
        returnComment = in.readString();
        date = in.readLong();
        num = in.readInt();
        userName = in.readString();
        userId = in.readInt();
        totalDamageNum = in.readInt();
    }

    public static final Creator<BorrowBean> CREATOR = new Creator<BorrowBean>() {
        @Override
        public BorrowBean createFromParcel(Parcel in) {
            return new BorrowBean(in);
        }

        @Override
        public BorrowBean[] newArray(int size) {
            return new BorrowBean[size];
        }
    };

    public long getDate() {
        return date;
    }

    public void setDate(long date) {
        this.date = date;
    }

    public int getNum() {
        return num;
    }

    public void setNum(int num) {
        this.num = num;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public int getUserId() {
        return userId;
    }

    public void setUserId(int userId) {
        this.userId = userId;
    }

    public int getApplyId() {
        return applyId;
    }

    public void setApplyId(int applyId) {
        this.applyId = applyId;
    }

    public String getApproveUserId() {
        return approveUserId;
    }

    public void setApproveUserId(String approveUserId) {
        this.approveUserId = approveUserId;
    }

    public String getApproveUserName() {
        return approveUserName;
    }

    public void setApproveUserName(String approveUserName) {
        this.approveUserName = approveUserName;
    }

    public String getBorrowTitle() {
        return borrowPersonName + "提交的借用单";
    }

    public String getBorrowOrganizationName() {
        return borrowOrganizationName;
    }

    public void setBorrowOrganizationName(String borrowOrganizationName) {
        this.borrowOrganizationName = borrowOrganizationName;
    }

    public String getNote() {
        return note;
    }

    public void setNote(String note) {
        this.note = note;
    }

    public List<SortBean> getBorrowSortViewList() {
        return borrowSortViewList;
    }

    public void setBorrowSortViewList(List<SortBean> borrowSortViewList) {
        this.borrowSortViewList = borrowSortViewList;
    }

    public List<ProductBean> getBorrowProductViewList() {
        return borrowProductViewList;
    }

    public void setBorrowProductViewList(List<ProductBean> borrowProductViewList) {
        this.borrowProductViewList = borrowProductViewList;
    }

    public String getBorrowCompanyName() {
        return borrowCompanyName;
    }

    public void setBorrowCompanyName(String borrowCompanyName) {
        this.borrowCompanyName = borrowCompanyName;
    }

    public String getBorrowPersonDepartment() {
        if (borrowPersonDepartment == null || borrowPersonDepartment.isEmpty()) {
            borrowPersonDepartment = borrowOrganizationName;
        }
        return borrowPersonDepartment == null ? "" : borrowPersonDepartment;
    }

    public void setBorrowPersonDepartment(String borrowPersonDepartment) {
        this.borrowPersonDepartment = borrowPersonDepartment;
    }

    public String getBorrowName() {
        if (borrowName == null || borrowName.isEmpty()) {
            borrowName = borrowPersonName + "提交的借用单";
        }
        return borrowName;
    }

    public void setBorrowName(String borrowName) {
        this.borrowName = borrowName;
    }

    public int getStockNum() {
        return stockNum;
    }

    public void setStockNum(int stockNum) {
        this.stockNum = stockNum;
    }

    public int getLendNum() {
        return lendNum;
    }

    public void setLendNum(int lendNum) {
        this.lendNum = lendNum;
    }

    public String getCheckDate() {
        return checkDate;
    }

    public void setCheckDate(String checkDate) {
        this.checkDate = checkDate;
    }

    public String getMoReturnDate() {
        return moReturnDate == null ? "" : moReturnDate;
    }

    public void setMoReturnDate(String moReturnDate) {
        this.moReturnDate = moReturnDate;
    }

    public String getReturnDate() {
        return returnDate;
    }

    public void setReturnDate(String returnDate) {
        this.returnDate = returnDate;
    }

    public int getApplyNum() {
        return applyNum;
    }

    public void setApplyNum(int applyNum) {
        this.applyNum = applyNum;
    }

    public int getBorrowPersonId() {
        return borrowPersonId;
    }

    public void setBorrowPersonId(int borrowPersonId) {
        this.borrowPersonId = borrowPersonId;
    }

    public String getBorrowComment() {
        return borrowComment;
    }

    public void setBorrowComment(String borrowComment) {
        this.borrowComment = borrowComment;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getCount() {
        return count;
    }

    public void setCount(String count) {
        this.count = count;
    }

    public int getDealtNum() {
        return dealtNum;
    }

    public void setDealtNum(int dealtNum) {
        this.dealtNum = dealtNum;
    }

    public int getBorrowId() {
        return borrowId;
    }

    public void setBorrowId(int borrowId) {
        this.borrowId = borrowId;
    }

    public String getBorrowPersonName() {
        return borrowPersonName;
    }

    public void setBorrowPersonName(String borrowPersonName) {
        this.borrowPersonName = borrowPersonName;
    }

    public String getBorrowApprover() {
        return borrowApprover;
    }

    public void setBorrowApprover(String borrowApprover) {
        this.borrowApprover = borrowApprover;
    }

    public String getBorrowCode() {
        return borrowCode;
    }

    public String getBorrowCode(String title) {
        return title + (borrowCode == null ? "" : borrowCode);
    }

    public void setBorrowCode(String borrowCode) {
        this.borrowCode = borrowCode;
    }

    public String getBorrowDate() {
        if (borrowDate == null || borrowDate.isEmpty()) {
            borrowDate = applyDate;
        }
        return borrowDate;
    }

    public void setBorrowDate(String borrowDate) {
        this.borrowDate = borrowDate;
    }

    public String getApplyDate() {
        return applyDate == null ? "" : applyDate;
    }

    public void setApplyDate(String applyDate) {
        this.applyDate = applyDate;
    }

    public String getApplyComment() {
        if (applyComment == null || applyComment.isEmpty()) {
            applyComment = getNote();
        }
        return applyComment == null ? "" : applyComment;
    }

    public void setApplyComment(String applyComment) {
        this.applyComment = applyComment;
    }

    public int getReturnNum() {
        return returnNum;
    }

    public void setReturnNum(int returnNum) {
        this.returnNum = returnNum;
    }

    public List<SortBean> getSortList() {
        return sortList;
    }

    public void setSortList(List<SortBean> sortList) {
        this.sortList = sortList;
    }

    public boolean isVisableNum(boolean visable) {
        List<SortBean> sortList = getSortList();
        if (sortList == null || sortList.isEmpty()) {
            return false;
        }
        int total = 0;
        int totalApply = 0;
        for (SortBean sortBean : sortList) {
            Integer lendNum = sortBean.getLendNum();
            if (lendNum != null) {
                total += lendNum;
            }
            Integer applyNum = sortBean.getApplyNum();
            if (applyNum != null) {
                totalApply += applyNum;
            }
        }
        this.borrowTotalTextNum = total + "/" + totalApply;
        return visable && total > 0;
    }

    public String getBorrowTotalTextNum(String title) {
        return title + " (" + borrowTotalTextNum + ")";
    }

    public boolean isRemandVisableNum(boolean visable) {
        return visable && returnNum > 0;
    }

    public String getRemandTotalTextNum(String title) {
        return title + " (" + returnNum + "/" + lendNum + ")";
    }

    public String getReturnComment() {
        return returnComment;
    }

    public void setReturnComment(String returnComment) {
        this.returnComment = returnComment;
    }

    public int getTotalDamageNumInt() {
        totalDamageNum = 0;
        List<SortBean> sortList = getSortList();
        if (sortList == null || sortList.isEmpty()) {
            return totalDamageNum;
        }
        for (SortBean sortBean : sortList) {
            Integer damageNum = sortBean.getDamageNum();
            if (damageNum != null) {
                totalDamageNum += damageNum;
            }
        }
        return totalDamageNum;
    }

    public int getTotalDamageNum() {
        return totalDamageNum;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(code);
        dest.writeString(count);
        dest.writeInt(lendNum);
        dest.writeInt(dealtNum);
        dest.writeInt(returnNum);
        dest.writeInt(applyNum);
        dest.writeInt(borrowId);
        dest.writeInt(applyId);
        dest.writeString(borrowPersonName);
        dest.writeString(borrowApprover);
        dest.writeString(approveUserName);
        dest.writeString(approveUserId);
        dest.writeString(checkDate);
        dest.writeString(moReturnDate);
        dest.writeString(returnDate);
        dest.writeString(borrowDate);
        dest.writeString(applyDate);
        dest.writeString(borrowCode);
        dest.writeString(borrowPersonDepartment);
        dest.writeString(borrowOrganizationName);
        dest.writeString(borrowName);
        dest.writeString(borrowCompanyName);
        dest.writeString(borrowComment);
        dest.writeString(applyComment);
        dest.writeString(note);
        dest.writeString(borrowTotalTextNum);
        dest.writeInt(borrowPersonId);
        dest.writeInt(stockNum);
        dest.writeTypedList(sortList);
        dest.writeTypedList(borrowSortViewList);
//        dest.writeTypedList(borrowProductViewList);
        dest.writeString(returnComment);
        dest.writeLong(date);
        dest.writeInt(num);
        dest.writeString(userName);
        dest.writeInt(userId);
        dest.writeInt(totalDamageNum);
    }
}
